<template>
  <div>
    <div style="padding: 10px 60px 5px 60px">
      <el-form :inline="true" :model="formInline"  class="demo-form-inline">

        <div class="text">订单查询</div>
        <br/>
        <el-form-item label="用户名">
          <el-input v-model="formInline.username" placeholder="username"></el-input>
        </el-form-item>
        <el-form-item >
          <el-button type="primary" @click="onSubmit" style="width: 100px;margin: 0 20px;">查询</el-button>
          <el-button style="width: 100px;margin: 0 0px;">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div style="padding: 5px 30px">
      <div class="text1">查询结果</div>
      <el-table
        ref="singleTable"
        :data="tableData"
        highlight-current-row
        @current-change="handleCurrentChange"
        style="width: 100%">
        <el-table-column
          type="index"
          width="50">
        </el-table-column>
        <el-table-column
          property="orderId"
          label="订单ID"
          width="180">
        </el-table-column>
        <el-table-column
          property="username"
          label="用户名"
          width="180">
        </el-table-column>
        <el-table-column
          property="initTime"
          label="生成订单时间"
          width="180">
        </el-table-column>
        <el-table-column
          property="payTime"
          label="支付时间"
          width="180">
        </el-table-column>
        <el-table-column
          label="查看详情">
          <template slot-scope="scope">
            <router-link  :to="{path: '/ordermanage/orderproducts',
          query: {orderId: scope.row.orderId,username: scope.row.username}}">
              <el-button @click="handleEdit(scope.$index, scope.row)"
                         size="mini"
                         type="danger"
              >查看订单商品详情</el-button>
            </router-link>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        formInline: {
          username: '',
        },
        tableData:[],
        currentRow:1
      }
    },

    methods: {
      setCurrent(row) {
        this.$refs.singleTable.setCurrentRow(row);
      },
      handleCurrentChange(val) {
        this.currentRow = val;
      },
      handleEdit(index, row) {
        console.log(index, row);
      },
      onSubmit() {
        let search={
          username:this.formInline.username
        }

        this.$axios({
          header:{
            "Content-Type": "application/json"
          },
          method:"post",
          url:"http://localhost:8080/api/order/searchorderbyusername",
          data:{
            username:search.username
          }
        }).then((res)=>{
          if(res.data.resultCode==="0"){
            this.$message({
              message: '查询成功',
              type: 'success'
            });
            this.tableData=res.data.orderViewList;
          }
        }).catch((error)=>{
          console.log(error);
        })
        console.log('submit!');
      }
    }
  }
</script>

<style scoped>
  .text {
    font-size: 30px;
    line-height: 46px;
    text-align: center;
  }
  .text1 {
    font-size: 20px;
    line-height: 30px;
    text-align: center;
  }
  .el-table .warning-row {
    background: oldlace;
  }
  .el-table .success-row {
    background: #f0f9eb;
  }
</style>
